<template>
	<view class="jh_content">
		<u-form class="jh_FormBox" :model="form">
			<!-- <u-form-item style="margin-left: 10rpx;" :label-position="labelPosition" label="原密码" label-width="150" prop="password">
				<u-input :password-icon="true" :border="border" type="password" v-model="form.password" placeholder="请输入原密码"></u-input>
			</u-form-item> -->
			<u-form-item style="margin-left: 10rpx;" :label-position="labelPosition" label="新密码" label-width="150" prop="newPassword">
				<u-input :password-icon="true" :border="border" type="password" v-model="form.newPassword" placeholder="请输入新密码"></u-input>
			</u-form-item>
			<u-form-item style="margin-left: 10rpx;" :label-position="labelPosition" label="确认密码" label-width="150" prop="rePassword">
				<u-input :border="border" type="password" v-model="form.rePassword" placeholder="请输入确认密码"></u-input>
			</u-form-item>
			<u-form-item style="margin-left: 10rpx;" :label-position="labelPosition" label="手机号" label-width="150" prop="phone">
				<u-input :border="border" v-model="form.phone" placeholder="请输入手机号"></u-input>
			</u-form-item>
			<u-form-item style="margin-left: 10rpx;" :label-position="labelPosition" label="验证码" prop="code" label-width="150">
				<u-input :border="border" placeholder="请输入验证码" v-model="form.code" type="text"></u-input>
				<u-button slot="right" type="success" style="margin-right: 10rpx;" size="mini" @click="getCode">{{codeTips}}</u-button>
			</u-form-item>
		</u-form>
		<u-verification-code seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
		<view style="padding:20upx 0;margin-top: 20rpx;">
			<button @click="submitState" class="jh_button">
				<text style="color: #FFFFFF;">提交修改</text>
			</button>
		</view>
	</view>
</template>

<script>
	var _self;
	export default {
		data() {
			return {
				form:{
					password:'',
					newPassword:'',
					rePassword:'',
					code:''
				},
				labelPosition: 'left',
				border: false,
				codeTips:''
			}
		},
		onLoad() {
			_self = this;
		},
		methods: {
			//-----------------------------获取验证码-----------------------------
			getCode:function(){
				console.log('获取验证码');
				if(_self.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码',
						mask: true
					})
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						_self.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						_self.$refs.uCode.start();
					}, 2000);
				} else {
					_self.$u.toast('倒计时结束后再发送');
				}
			},
			codeChange(text) {
				_self.codeTips = text;
			},
			submitState:function(){
				if(!_self.form.password || !_self.form.newPassword || !_self.form.rePassword){
					if(!_self.form.newPassword){
						_self.$u.toast('新密码不能为空');
					}else if(!_self.form.rePassword){
						_self.$u.toast('确认密码不能为空');
					}
				}else if(_self.form.password != '123'){
					_self.$u.toast('原密码有误');
				}else if(_self.form.password == _self.form.newPassword){
					_self.$u.toast('新密码不能与旧密码一致');
				}else if(_self.form.newPassword != _self.form.rePassword){
					_self.$u.toast('两次输入的密码不一致，请确认后重新输入');
				}else if(!_self.form.code){
					_self.$u.toast('请输入验证码');
				}else if(_self.form.code != '123'){
					_self.$u.toast('输入的验证码有误，请重新输入');
				}else{
					console.log('修改成功');
					uni.navigateBack();
				}
			}
		}
	}
</script>

<style>

</style>
